package com.level2app.ui.login.view;

import androidx.lifecycle.MutableLiveData;

import com.level2app.base.BaseViewModel;
import com.level2app.bean.MessageBean;
import com.level2app.di.retrofit.BaseNetCallback;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by S
 * time 2024/8/13
 */
public class EmailLoginViewModel extends BaseViewModel {
    public MutableLiveData<String> inputEmail = new MutableLiveData<>();
    public MutableLiveData<MessageBean> sendSuccessData = new MutableLiveData<>();
    public MutableLiveData<String> sendFailedData = new MutableLiveData<>();

    public void sendEmailLogin(String email) {
        Map<String, Object> map = new HashMap<>();
        map.put("email", email);
        map.put("platform", "android");
        addSubscribe(mRetrofitHelper.sendLoginMail(map).subscribeWith(new BaseNetCallback<MessageBean>(){

            @Override
            public void onSuccess(MessageBean baseModel) {
                sendSuccessData.setValue(baseModel);
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                sendFailedData.setValue(message);
            }
        }));
    }

    public void sendEmailRegister(String email) {
        Map<String, Object> map = new HashMap<>();
        map.put("email", email);
        map.put("content", "string");
        addSubscribe(mRetrofitHelper.sendRegisterMail(map).subscribeWith(new BaseNetCallback<MessageBean>(){

            @Override
            public void onSuccess(MessageBean baseModel) {
                sendSuccessData.setValue(baseModel);
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                sendFailedData.setValue(message);
            }
        }));
    }
}